<!DOCTYPE html>
<html>
<head>
    <title>房源签认主界面</title>
<#include "../common/common.ftl"/>
</head>
<body>
<div class="layui-fluid">
    <form class="layui-form">
        <div class="layui-card">
            <div class="layui-card-header">一、被动迁人基本信息
                <button type="button" class="layui-btn jmdf-btn-view viewChoose"><i
                        class="layui-icon layui-icon-rate-solid" style="position:static;"></i>查看费用明细
                </button>
                <button type="button" class="layui-btn setIsJiSuan">享受优惠面积信息管理</button>
            </div>
            <div class="layui-card-body">
                <div class="layui-form-item">
                    <div class="layui-col-xs4">
                        征收项目：${(contract.zsProject.projectName)!}
                    </div>
                    <div class="layui-col-xs4">
                        协议编号：${(contract.contractCode)!}
                    </div>
                    <div class="layui-col-xs4">
                        选房顺序号：${(contract.chooseHouseNum)!}
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-xs4">
                        被动迁人：${(contract.name)!}
                    </div>
                    <div class="layui-col-xs4">
                        身份证号：${(contract.idCard)!}
                    </div>
                    <div class="layui-col-xs4">
                        原可选房面积：【<span class="jmdf-color-green">${(contract.yazArea)!}</span>】㎡
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-xs4">
                        产权参与合并（-代表减少）：【<span class="jmdf-color-orange">${(contract.adjustArea)!}</span>】㎡
                    </div>
                    <div class="layui-col-xs4">
                        照顾参与合并（-代表减少）：${(contract.adjustZgArea)!}
                    </div>
                    <div class="layui-col-xs4">
                        现可选房面积：【<span class="jmdf-color-red">${(contract.limitHouseAreaTotal)!}</span>】㎡
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-header">二、请选择安置项目及房源</div>
            <div class="layui-card-body">
                <div class="layui-form-item">
                    <div class="layui-col-xs12">
                    <#if (azProjectIdList?size > 0)>
                        <#list azProjectIdList as azProjectId>
                            <#assign azProject=azProjectMap[azProjectId?c]/>
                            <a class="layui-btn loadAzProject" azProjectId="${(azProject.id)!}"><i
                                    class="layui-icon layui-icon-home"></i>${(azProject.projectName)!}</a>
                        </#list>
                    </#if>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-header">三、已选房源<#--及其配套储藏室【注：<span class="jmdf-color-red">若要撤销房源，需先撤销该房源配套的储藏室</span>】-->
                <button type="button" class="layui-btn jmdf-btn-print chooseResultPrint"><i
                        class="layui-icon layui-icon-rate-solid" style="position:static;"></i>打印房源（预选）签认表
                </button>
                <button type="button" class="layui-btn chooseHouseStatus
                    <#if contract.chooseHouseStatus == 2> layui-btn-danger</#if>" contractId="${(contract.id)!}">
                <#if contract.chooseHouseStatus == 1>设置为已签认<#else>设置为未签认</#if>
                </button>
            </div>
            <#--<div class="layui-card-body">
                <div class="layui-col-xs12">
                <#if (azProjectIdList?size > 0)>
                    <#list azProjectIdList as azProjectId>
                        <#assign azProject=azProjectMap[azProjectId?c]/>
                        <a class="layui-btn loadAzProjectStorageRoom" azProjectId="${(azProject.id)!}"><i
                                class="layui-icon layui-icon-home"></i>${(azProject.projectName)!}</a>
                    </#list>
                </#if>
                </div>
            </div>-->
        </div>
        <div class="layui-card-body" id="selectHouseInfo"></div>
        <div class="layui-card">
            <div class="layui-card-header">
                四、已选车位　<#if (contract.chooseHouseStatus == 1)>
                <button type="button" class="layui-btn carLotAdd">选择车位</button></#if>
            </div>
            <div class="layui-card-body">
                <table class="layui-table" lay-filter="layFilter" id="carLotTable"></table>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-header">
                五、已选店铺　<#if (contract.chooseHouseStatus == 1)>
                <button type="button" class="layui-btn loadAzProjectShopHouse">选择店铺</button></#if>
            </div>
            <div class="layui-card-body" id="selectShopHouseInfo"></div>
        </div>
    </form>
</div>
<script type="text/html" id="indexTpl">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<!--菜单-->
<script type="text/html" id="carLotTable_toolbar">
    <#if (contract.chooseHouseStatus == 1)>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="carLotTable_delete"><i
            class="layui-icon layui-icon-delete"></i>撤销车位</a>
    </#if>
</script>
<script src="/layui/layui.js" charset="utf-8"></script>
<script>
    layui.config({
        base: '/modules/' //静态资源所在路径
    }).use(['jquery', 'jmdf', 'form', 'table'], function () {
        var $ = layui.jquery, jmdf = layui.jmdf, form = layui.form, table = layui.table, parentIndex = parent.layer.getFrameIndex(window.name);

        $(".loadAzProject").click(function () {
            var obj = $(this);
            jmdf.view("housePicture?contractId=${(contract.id)!}&azProjectId=" + obj.attr("azProjectId"), "90");
            $(".loadAzProject").removeClass("layui-btn-danger");
            obj.addClass("layui-btn-danger")
        });
        $(".loadAzProjectStorageRoom").click(function () {
            var obj = $(this);
            jmdf.view("storageRoomList?type=1&contractId=${(contract.id)!}&azProjectId=" + obj.attr("azProjectId"), "90");
        });

        $(".carLotAdd").click(function () {
            jmdf.view("carLotList?contractId=${(contract.id)!}", "80");
        });
        $(".loadAzProjectShopHouse").click(function () {
            var obj = $(this);
            jmdf.view("shopHouseList?contractId=${(contract.id)!}&azProjectId=" + obj.attr("azProjectId"), "90");
        });
        form.render();

        //列项内容
        var cols = [[
            {title: "序号", toolbar: '#indexTpl', type: "numbers", fixed: 'left', align: 'center', width: 60}
            , {field: "projectName", title: "安置项目", align: 'center', width: 200}
//            , {field: "buildNum", title: "幢号", align: 'center'}
//            , {field: "houseNum", title: "户号", align: 'center'}
//            , {field: "floor", title: "所在层数", align: 'center'}
            , {field: "carLotInfo", title: "车位信息", align: 'center'}
            , {field: "buildArea", title: "建筑面积(㎡)", align: 'center'}
            , {field: "carLotTypeStr", title: "车位类型", align: 'center'}
            , {title: '操作', fixed: 'right', align: 'center', toolbar: '#carLotTable_toolbar', width: 200}
        ]];

        //table设置项
        var options = {
            elem: '#carLotTable' //table列表id值
            , url: "loadSelectCarLotInfo?contractId=${(contract.id)!}"
            , cols: cols
            , id: "renderId"
        };
        table.render(options);

        table.on("tool(layFilter)", function (obj) {
            var data = obj.data;///获得当前行数据
            var layEvent = obj.event;//获得lay-event对应的值
            var id = data["id"];
            if (layEvent == "carLotTable_delete") {
                layer.open({
                    title: false,
                    shade: 0.5,
                    content: "确定要撤销【" + data['carLotInfo'] + "】车位吗？",
                    btn: ['确定', '取消'],
                    closeBtn: 0,
                    btnAlign: 'c'
                    ,
                    yes: function (index) {
                        $.get("carLotDelete", {carLotId: data["id"], _time: new Date().getTime()}, function (data) {
                            if (data.code == "0001") {//成功
                                layer.msg(data.message, {anim: 0, icon: 1, time: 1000}, function () {
                                    reloadSelectCarLotInfo();
                                });
                            } else {//失败
                                layer.msg(data.message, {anim: 6, icon: 2, time: 3000});
                            }
                            layer.close(index);
                        });
                    }
                });
            }
        });

        function reloadSelectCarLotInfo() {
            table.reload("renderId", {});
        }

        //房源
        function loadSelectHouseInfo(contractId) {
            $.get("selectHouseInfo", {contractId: contractId, _time: new Date().getTime()}, function (data) {
                $("#selectHouseInfo").html(data);
            });
        }

        loadSelectHouseInfo("${(contract.id)!}");
        //店铺
        function loadSelectShopHouseInfo(contractId) {
            $.get("selectShopHouseInfo", {contractId: contractId, _time: new Date().getTime()}, function (data) {
                $("#selectShopHouseInfo").html(data);
            });
        }

        loadSelectShopHouseInfo("${(contract.id)!}");


        window.loadSelectHouseInfo = loadSelectHouseInfo;
        window.loadSelectShopHouseInfo = loadSelectShopHouseInfo;
        window.reloadSelectCarLotInfo = reloadSelectCarLotInfo;


        //查看计算信息
        $(".viewChoose").click(function () {
            jmdf.view("viewChoose?contractId=${(contract.id)!}", "40");
        });

        //设置剩余面积是否结算
        $(".setIsJiSuan").click(function () {
            jmdf.minForm("areaJieSuanForm?contractId=${(contract.id)!}", "860px", "260px");
        });
        //打印签认表
        $(".chooseResultPrint").click(function () {
            $.ajax({//选房顺序号非重验证
                url: 'getIsMustBigHouse',
                type: 'post',
                data: {
                    contractId: '${(contract.id)!}'
                },
                async: false,
                success: function (data) {
                    isMustBigHouse = data;
                }
            });

            if (isMustBigHouse == true) {
                jmdf.print("chooseResultPrint?contractId=${(contract.id)!}", "50");
            } else {
                alert("请先仔细核对该户选房方案，若无误，请联系技术支持取消选房限制！");
            }
        });

        //设置签认状态
        $(".chooseHouseStatus").click(function () {
            var msg = '${contract.financeCheckStatus}' == 1 ? "已签认" : "未签认";
            layer.open({
                title: false,
                shade: 0.5,
                content: "确认设置为" + msg + "吗？设置后房源不可修改！",
                btn: ['确定', '取消'],
                closeBtn: 0,
                btnAlign: 'c'
                ,
                yes: function (index) {
                    $.get("chooseHouseStatus", {
                        contractId: '${(contract.id)!}',
                        _time: new Date().getTime()
                    }, function (data) {
                        if (data.code == "0001") {//成功
                            parent.loadData();
                            layer.msg(data.message, {anim: 0, icon: 1, time: 1000}, function () {
                                location.reload();
                            });
                        } else {//失败
                            layer.msg(data.message, {anim: 6, icon: 2, time: 3000});
                        }
                        layer.close(index);
                    });
                }
            });
        })
    });
</script>
</body>
</html>